package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.dto.DeviceDto;
import com.zzyl.nursing.vo.DeviceVo;
import com.zzyl.nursing.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.Device;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * deviceController
 * 
 * @author gyf
 * @date 2025-01-10
 */
@Api(tags = "设备管理")
@RestController
@RequestMapping("/nursing/device")
public class DeviceController extends BaseController
{
    @Autowired
    private IDeviceService deviceService;

    /**
     * 查询device列表
     */
    @ApiOperation("查询device列表")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @GetMapping("/list")
    public TableDataInfo<List<Device>> list(@ApiParam("device查询条件") Device device)
    {
        startPage();
        List<Device> list = deviceService.selectDeviceList(device);
        return getDataTable(list);
    }

    /**
     * 同步IoT产品列表到redis
     * @return
     */
    @PostMapping("/syncProductList")
    public AjaxResult syncProductList() {
        deviceService.syncProductList();
        return AjaxResult.success();
    }

    /**
     * 查询所有产品
     * @return
     */
    @GetMapping("/allProduct")
    public R<List<ProductVo>> allProduct() {
        return R.ok(deviceService.allProduct());
    }


    /**
     * 注册设备
     * @param deviceDto
     * @return
     */
    @PostMapping("/register")
    public AjaxResult registerDevice(@RequestBody DeviceDto deviceDto){
       deviceService.registerDevice(deviceDto);
        return success();
    }

    /**
     * 查询设备详情
     * @param deviceDto
     * @return
     */
    @PostMapping("/queryDeviceDetail")
    public R<DeviceVo>  queryDeviceDetail(@RequestBody DeviceDto deviceDto){
        return R.ok(deviceService.queryDeviceDetail(deviceDto));
    }

    /**
     * 查看指定产品的已发布物模型中的功能定义详情
     * @param deviceDto
     * @return
     */
    @PostMapping("/queryThingModelPublished")
    public AjaxResult queryThingModelPublished(@RequestBody DeviceDto deviceDto){
        return deviceService.queryThingModelPublished(deviceDto);
    }

    /**
     * 查询指定设备的物模型运行状态
     * @param request
     * @return
     */
    @PostMapping("/queryDevicePropertyStatus")
    public AjaxResult queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request){
        return deviceService.queryDevicePropertyStatus(request);
    }


    @PutMapping
    public AjaxResult updateDevice(@RequestBody Device device){
        deviceService.updateDevice(device);
        return success();
    }

    @DeleteMapping
    public AjaxResult deleteDevice(@RequestBody Device device){
        deviceService.deleteDevice(device);
        return success();
    }
}
